package cn.xyinping._04_direct;


import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 27266
 * @desrciption
 * @date 2021/11/12
 */
public class Producer {
    // 交换机名
    public final static String PRODUCER_EXCHANGE_NAME_DIRECT = "exchange_name_direct1111";
    public static void main(String[] args) throws IOException, TimeoutException {
        // 1. 创建RabbitMQ链接
        ConnectionFactory factory  = new ConnectionFactory();

        Connection connection = factory.newConnection();
        // 2. 创建通道
        Channel channel = connection.createChannel();
        // 创建交换机
        channel.exchangeDeclare(PRODUCER_EXCHANGE_NAME_DIRECT, BuiltinExchangeType.DIRECT);
        // 4. 发送消息 error warn debug info
        channel.basicPublish(PRODUCER_EXCHANGE_NAME_DIRECT, // 使用交换机
                "info", // 队列名 Fanout模式不需要指定routingKey
                null, // 其他参数
                "大海我来了！".getBytes()); // 要发送的信息 要byte数组
        System.out.println("成功");

    }

}
